package com.rotsel.mh3udb.app.Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.rotsel.mh3udb.app.ListModels.NumberIconTextModel;
import com.rotsel.mh3udb.app.R;

import java.util.ArrayList;

/**
 * Created by rots on 20.02.14.
 */
public class NumberIconTextAdapter extends ArrayAdapter<NumberIconTextModel> {
    private Context context;
    private ArrayList<NumberIconTextModel> modelArrayList;

    public NumberIconTextAdapter(Context cont, ArrayList<NumberIconTextModel> list){
        super(cont, R.layout.number_icon_text_list_item, list);

        this.context = cont;
        this.modelArrayList = list;
    }

    @Override
    public long getItemId(int position) {
        return modelArrayList.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.number_icon_text_list_item, parent, false);

        TextView numberView = (TextView)rowView.findViewById(R.id.number);
        ImageView iconView = (ImageView)rowView.findViewById(R.id.icon);
        TextView textView = (TextView)rowView.findViewById(R.id.text);

        numberView.setText(modelArrayList.get(position).getNumber());
        iconView.setImageResource(modelArrayList.get(position).getIcon());
        textView.setText(modelArrayList.get(position).getText());

        return rowView;
    }
}
